package simtester.cloud

class Utils {
    static def waitFor(args, Closure closure) {
        def count = 0
        while (count < args.limit) {
            def done = closure.call()
            if (done == true) {
                break
            }
            
            sleep args.step
            count += args.step
        }
        
        if (count >= args.limit) {
            throw new TimeoutException('Operation timed out')
        }
        
        return count
    }
}
